import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;


public class RankMachine {
	
	BufferedReader reader = null;
	StringBuffer posSeeds = new StringBuffer();
	StringBuffer negSeeds = new StringBuffer();
	
	public RankMachine()throws Exception{
		String posFile = this.getClass().getResource("/").getPath()+"\\res\\positiveSeeds.txt";
		String negFile = this.getClass().getResource("/").getPath()+"\\res\\negativeSeeds.txt";
		String line = new String();
		
		reader = new BufferedReader(new InputStreamReader(new FileInputStream(posFile)));
		while((line=reader.readLine())!=null){
			posSeeds.append(line);
		}
		reader.close();
		
		reader = new BufferedReader(new InputStreamReader(new FileInputStream(negFile)));
		while((line=reader.readLine())!=null){
			negSeeds.append(line);
		}
		reader.close();
		
	}
	
	public int getScore(String restId){
		int score = 0;
		String[] posTerms = posSeeds.toString().split(" ");
		String[] negTerms = negSeeds.toString().split(" ");
		boolean noFlag = false;
		
		//get the full review of this restaurant
		String fullReview = "";
		String[] temp = fullReview.split(" ");
		for(int m=0; m<temp.length; m++){
			if (temp[m].equals("not")||temp[m].equals("no")||temp[m].equals("n't")){
				noFlag = true;
				System.out.print(temp[m]+" ");
			}
			for(int i=0; i<posTerms.length; i++){
				if(posTerms[i].equals(temp[m])){
					if(noFlag){
						score--;
						System.out.print(temp[m]+" ");
						System.out.println(score);
					}else{
						score++;
						System.out.print(temp[m]+" ");
						System.out.println(score);
					}
					break;
				}
			}
			for(int j=0; j<negTerms.length; j++){
				if(negTerms[j].equals(temp[m])){
					if(noFlag){
						score++;
						System.out.print(temp[m]+" ");
						System.out.println(score);
					}else{
						score--;
						System.out.print(temp[m]+" ");
						System.out.println(score);
					}
					break;
				}	
			}
		}
		return score;
	}
}
